package com.settlement.system.converter;

import com.alibaba.excel.converters.string.StringStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.settlement.system.common.enums.ViewDeliveryTypeEunm;
import org.apache.commons.lang3.StringUtils;

/**
 * @author author
 */
public class ViewDeliveryTypeConvert extends StringStringConverter {

    @Override
    public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {

        if(!StringUtils.isEmpty(value)){
            ViewDeliveryTypeEunm[] statusEunms = ViewDeliveryTypeEunm.values();
            for(int index = 0;index < statusEunms.length;index++){
                if(statusEunms[index].getNo().equals(value)){
                    return new WriteCellData(statusEunms[index].getName());
                }
            }
        }
        return new WriteCellData();
    }

    @Override
    public String convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String value = cellData.getStringValue();
        if(!StringUtils.isEmpty(value)){
            String noByName = ViewDeliveryTypeEunm.getNoByName(value);
            if(StringUtils.isEmpty(noByName)){
                return value;
            }
            return noByName;
        }
        return null;
    }
}
